dofile("KNEEBOARD_MOD_PeterP/data/KNEEBOARD/indicator/definitions.lua")
SetScale(FOV)
SetCustomScale(GetScale())

set_clip_by_planes(true)

local  geo_center  	     = lo_to_geo_coords(0,0)
local  geo_up_right      = lo_to_geo_coords(10000,10000)
local  lo_1   			 = geo_to_lo_coords(geo_center.lat + 0.1,geo_center.lon)
local  lo     			 = geo_to_lo_coords(geo_center.lat      ,geo_center.lon + 0.1)

local  dist_1                = math.sqrt(lo_1.z * lo_1.z + lo_1.x * lo_1.x) * 10
local  meters_per_lon_degree = math.sqrt(lo.x * lo.x     + lo.z * lo.z) * 10
default_aspect 		  		 = meters_per_lon_degree/dist_1

set_lat_lon_aspect(default_aspect)

local FONT_   	 = MakeFont({used_DXUnicodeFontData = "FUI/Fonts/font_dejavu_lgc_sans_22"},{0,225,0,255},10,"dejavu_lgc_sans_22")
local tex_coords = {{0,1},{0,0},{1,0}, {1,1}}
local indices    = {0,1,2;0,2,3}

function tad_chart(chart_id,material,lat_min,lat_max,lon_min,lon_max,chart_aspect)


local chart		    = create_chart(chart_id,lat_min / default_aspect,lat_max / default_aspect,lon_min,lon_max)
local k 		    = chart_aspect / default_aspect

local sz_x =  0.5*(lat_max - lat_min) / chart_aspect
local sz_z =  0.5*(lon_max - lon_min) * chart_aspect / default_aspect

local	draw_lat_center = (lat_min + 0.5*(lat_max - lat_min))/default_aspect
local	draw_lon_center = (lon_min + 0.5*(lon_max - lon_min))

local 	element					= CreateElement "ceTexPoly"
		element.name 			= string.upper(material)
		element.primitivetype   = "triangles"
		element.material	   	= MakeMaterial("tad/"..material..'.bmp.dds',{255,255,255,255})
		element.vertices        = {{ -sz_x , -sz_z},
								   { -sz_x ,  sz_z},
								   {  sz_x ,  sz_z},
								   {  sz_x , -sz_z}}
		element.controllers		= {{"chart_position",draw_lat_center,
													 draw_lon_center,
													 GetScale()}}
		element.indices			= indices
		element.tex_coords		= tex_coords
		element.use_mipfilter 	= true
		element.h_clip_relation = h_clip_relations.COMPARE
		element.level 		    = DEFAULT_LEVEL
	    Add(element)
		chart:add_element(element)
end


-- loading map charts related to current terrain
mount_vfs_path_to_mount_point("/textures/tad/",get_terrain_related_data("TAD_vfs_archives"))
local map_set_file = get_terrain_related_data("TAD_chart_map_set_file") -- using a-10c charts by default
-- execute file
if map_set_file then
   dofile(map_set_file)
end


